import os

# os.system("dir")

# import subprocess
#
# p = subprocess.Popen(["java"], stdout=subprocess.PIPE, universal_newlines=True)
#
# p.wait()
#
# out = p.communicate()
# if p.returncode == 0:
#     print("success0")
#     print(out)
# else:
#     print("success3")
#     print(out)

# import os
#
# res = os.popen("dir").read()
#
# print(res)

import subprocess

# command = "netsh interface ip show address WAN | findstr IP"
# command = "dir"
# p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout
# # p = subprocess.Popen(command, shell=True).stdout
# print(p.read().decode('gbk'))

exec("print('76879')")
eval("print('76879')")

a = exec("2+3")  # 相当于直接执行 2+3，但是并没有返回值，a 应为 None
print(a)
a = eval('2+3')  # 执行 2+3，并把结果返回给 a
print(a)

import os, random
import sys

sys.stdout.write("122323##########")

demoString = """

print(os.path)

def add(a,b):\n\treturn a+b\n\nprint(add(12,23))
def add(a,b):\nreturn a+b\n\nprint(add(12,23))
print(random.randint(120,190))
"""

a = 10
b = 20
c = 30
g = {'os': os, 'b': 8, 'random': random}
t = {'b': 100, 'c': 10}
try:
    exec(demoString, g, t)
    print("1111111111111111111111111111")
except SyntaxError as e:
    # SyntaxError('invalid syntax', ('<string>', 8, 1, ';\n'))
    IndentationError('expected an indented block', ('<string>', 4, 1, 'print(os.path)\n'))
    print(repr(e))
    print(e)
    print(e.lineno)
    print(e.offset)
    print(e.msg)
    print(e.text)
except SyntaxError as e:
    # TypeError("add() missing 1 required positional argument: 'b'")
    print(e)
except Exception as e:
    print(e)

dictDemo = {"a": 10, "b": 20, "c": 30}
print(dictDemo)
dictDemo.pop("c")
print(dictDemo)
